package com.ratp.expertisetechnique;

import com.ratp.bean.Expertise;
import com.ratp.bean.UtilsBean;
import com.ratp.composants.CustomTextWatcher;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.widget.EditText;

public class SignalementEngageantMeca extends Activity {
	private EditText directionMecaEditText;
	private EditText freinsMecaEditText;
	private EditText moteurMecaEditText;
	private EditText boiteVitessMecaEditText;
	private EditText suspensionMecaEditText;
	private EditText transmissionMecaEditText;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.signalement_engageant_meca);
		initVariables();
		initEcouteurs();
	}

	/**
	 * Permet de garder les valeurs meme en changeant d'onglet
	 */
	private void initVariables() {
		directionMecaEditText = (EditText) findViewById(R.id.editDirectionMeca);
		freinsMecaEditText = (EditText) findViewById(R.id.editFreinsMeca);
		moteurMecaEditText = (EditText) findViewById(R.id.editMoteurMeca);
		boiteVitessMecaEditText = (EditText) findViewById(R.id.editBoiteVitessMeca);
		transmissionMecaEditText = (EditText) findViewById(R.id.editTransmissionMeca);
		suspensionMecaEditText = (EditText) findViewById(R.id.editSuspensionMeca);

		Expertise expertise = UtilsBean.getExpertiseInstance();

		directionMecaEditText.setText(expertise.getDirctionEngage());
		freinsMecaEditText.setText(expertise.getFreinsEngage());
		moteurMecaEditText.setText(expertise.getMoteurEngage());
		boiteVitessMecaEditText.setText(expertise.getBoiteVitessEngagee());
		transmissionMecaEditText.setText(expertise.getTransmissionEngage());
		suspensionMecaEditText.setText(expertise.getSuspensionEngage());
	}

	private void initEcouteurs() {
		directionMecaEditText.addTextChangedListener(new CustomTextWatcher() {
			@Override
			public void afterTextChanged(Editable s) {
				UtilsBean.getExpertiseInstance()
						.setDirctionEngage(s.toString());
			}
		});

		freinsMecaEditText.addTextChangedListener(new CustomTextWatcher() {
			@Override
			public void afterTextChanged(Editable s) {
				UtilsBean.getExpertiseInstance().setFreinsEngage(s.toString());
			}
		});
		moteurMecaEditText.addTextChangedListener(new CustomTextWatcher() {
			@Override
			public void afterTextChanged(Editable s) {
				UtilsBean.getExpertiseInstance().setMoteurEngage(s.toString());
			}
		});
		boiteVitessMecaEditText.addTextChangedListener(new CustomTextWatcher() {
			@Override
			public void afterTextChanged(Editable s) {
				UtilsBean.getExpertiseInstance().setBoiteVitessEngage(
						s.toString());
			}
		});
		transmissionMecaEditText
				.addTextChangedListener(new CustomTextWatcher() {
					@Override
					public void afterTextChanged(Editable s) {
						UtilsBean.getExpertiseInstance().setTransmissionEngage(
								s.toString());
					}
				});
		suspensionMecaEditText.addTextChangedListener(new CustomTextWatcher() {
			@Override
			public void afterTextChanged(Editable s) {
				UtilsBean.getExpertiseInstance().setSuspensionEngage(
						s.toString());
			}
		});
	}
}
